package IC.Tables.Types;

import IC.AST.*;
import IC.Semantic.SemanticError;

/**
 * User defined class type
 */

public class ClassType extends Type {
	private String super_name;
	private ICClass classAST;
	
	public ClassType(ICClass classAST){
		super(classAST.getName());
		this.super_name = classAST.getSuperClassName();
		this.classAST = classAST;
	}
	
	@Override
	public boolean subtypeOf(Type t){
		if (!(t instanceof ClassType)) return false;		
		if (t == this) return true;	
		
		if (this.super_name == null) return false;		
		else try{
			return TypeTable.getClassType(super_name).subtypeOf(t);
		} catch (SemanticError se){ 
			return false;
		}
	}
	
	public String toString(){
		String str = this.getName();

		if (this.classAST.hasSuperClass()){
			try {
				str += ", Superclass ID: "+TypeTable.getClassType(this.super_name).getTypeID();
			} catch (SemanticError se){} 
		}
		
		return str;
	}
}